package com.ee.chat.admin.controller.operatemanage;

import com.ee.chat.admin.service.IImService;
import com.ee.chat.common.bean.Result;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @Author AppiJ
 * @Date 2020/4/24 11:53
 */
@RestController
@RequestMapping("operate/im")
public class ImController {
    private Logger log = LoggerFactory.getLogger(ImController.class);

    @Resource
    IImService imService;

    /**
     * 获取消息列表
     * @Author AppiJ
     * @Date 2020/4/24 17:39
     * @return
     */
    @RequestMapping("list")
    public Result list(HttpServletRequest request, Integer fromUserId, Integer toUserId, String type,
                       String createTime, @RequestParam Integer page, @RequestParam Integer limit){
        try {
            return imService.list(request, fromUserId, toUserId, type, createTime, page, limit);
        } catch (Exception e){
            log.error("【查询消息列表错误】", e);
        }
        return Result.returnFailure();
    }

    /**
     * 处理消息
     * @Author AppiJ
     * @Date 2020/4/26 14:51
     * @param
     * @return
     */
    @RequestMapping("updateStatus")
    public Result updateStatus(HttpServletRequest request, @RequestParam("ids[]") List<Integer> ids){
        try {
            return imService.updateStatus(request, ids);
        } catch (Exception e){
            log.error("【处理消息错误】", e);
        }
        return Result.returnFailure();
    }

    /**
     * 查看聊天记录
     * @Author AppiJ
     * @Date 2020/4/26 17:04
     * @param
     * @return
     */
    @RequestMapping("view")
    public Result view(HttpServletRequest request, Integer kill, String time, Integer fromUserId,
                       Integer toUserId, String type, @RequestParam Integer page, @RequestParam Integer limit){
        try {
            return imService.view(request, kill, time, fromUserId, toUserId, type, page, limit);
        } catch (Exception e){
            log.error("【查看聊天记录错误】", e);
        }
        return Result.returnFailure();
    }

    /**
     * 查询查杀消息记录列表
     * @Author AppiJ
     * @Date 2020/4/27 16:56
     * @param
     * @return
     */
    @RequestMapping("kill")
    public Result kill(HttpServletRequest request, String date,  @RequestParam Integer page, @RequestParam Integer limit){
        try {
            return imService.kill(request, date, page, limit);
        } catch (Exception e){
            log.error("【查询查杀消息记录列表错误】", e);
        }
        return Result.returnFailure();
    }
}
